Imports System.Data
Imports System.Data.SqlClient
Partial Class Client_frmBillingAddress
    Inherits System.Web.UI.Page
    Dim _UserId As String
    Dim _bo As New Bo
    Dim _BillingAddressVo As New BillingAddressVO
    Dim dt As New DataTable
    Dim dt1 As New DataTable
    Dim tmpvar As String
    Dim dtcountryname As New DataTable
    Dim dr As DataRow
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _UserId = Session("UserId")
        If _UserId = "" Then
            Response.Redirect("frmLogin.aspx")
        End If
        If Not Page.IsPostBack Then
            dt = _bo.getUserDetail(_UserId)
            lblUserId.Text = _UserId
            Call CountryData() 
            For Each dr In dt.Rows
                txtFirstName.Text = dr("FirstName").ToString
                txtLastName.Text = dr("LastName").ToString
                txtAddress.Text = dr("Address").ToString
                ddlCountry.SelectedValue = dr("Country").ToString
                Call StateData()

                ddlState.SelectedValue = dr("State").ToString
                Call CityData()
                ddlCity.SelectedValue = dr("City").ToString
                txtPhoneNumber.Text = dr("PhoneNumber").ToString
                txtMobileNumber.Text = dr("MobileNumber").ToString
                txtZipCode.Text = dr("ZipCode").ToString
            Next
            dt1 = _bo.getBillDate(_UserId)
            lblBillId.Text = dt1.Rows(0).Item(0).ToString
            txtBillDate.Text = dt1.Rows(0).Item(1).ToString
        End If
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _bo.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _bo.getstate(ddlCountry.SelectedValue)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Sub CityData()
        Dim dtCity As DataTable
        dtCity = _bo.getCity(ddlState.SelectedValue)
        ddlCity.DataSource = dtCity
        ddlCity.DataValueField = dtCity.Columns(2).ToString
        ddlCity.DataTextField = dtCity.Columns(3).ToString
        ddlCity.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        Call StateData()
        Call CityData()
    End Sub
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        Call CityData()
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        _BillingAddressVo.UserId = _UserId
        _BillingAddressVo.Address = txtAddress.Text
        _BillingAddressVo.FirstName = txtFirstName.Text
        _BillingAddressVo.LastName = txtLastName.Text
        _BillingAddressVo.City = ddlCity.SelectedValue.ToString
        _BillingAddressVo.State = ddlState.SelectedValue.ToString
        _BillingAddressVo.Country = ddlCountry.SelectedValue.ToString
        _BillingAddressVo.PhoneNumber = txtPhoneNumber.Text
        _BillingAddressVo.Zipcode = txtZipCode.Text
        _BillingAddressVo.MobileNumber = txtMobileNumber.Text
        _BillingAddressVo.BillDate = txtBillDate.Text
        _BillingAddressVo.BillId = lblBillId.Text
        _bo.insertBillingAddress(_BillingAddressVo)
        Session("UserId") = _UserId
        Response.Redirect("frmShippingAddress.aspx")
        '    Response.Redirect("frmFeedback.aspx")
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAddress.Text = ""
        txtPhoneNumber.Text = ""
        txtMobileNumber.Text = ""
        txtZipCode.Text = ""
    End Sub
End Class
